public class OrderService {

    private final OrderLock orderLock = new OrderLock();

    //支付订单方法
    public void payment(Long orderId) {
        //支付订单，要修改订单订单状态为已支付
        if (!orderLock.getLock(orderId)) {
            //或抛出异常
            return;
        }

        System.out.println(orderId);

        //update status to paid

        orderLock.releaseLock(orderId);
    }

    //取消订单方法
    public void cancel(Long orderId) {
        if (!orderLock.getLock(orderId)) {
            //或抛出异常
            return;
        }

        System.out.println(orderId);
        //取消订单，要修改订单状态为已取消
        //update status to canceled

        orderLock.releaseLock(orderId);
    }
}
